﻿<CodeSnippetTabbed DocLink="https://docs.devexpress.com/Blazor/402066/common-concepts/validate-input">
<CodeSnippetTabPage Text="Razor">
@(@"<EditForm Model=""@starship"" OnValidSubmit=""@HandleValidSubmit"" OnInvalidSubmit=""@HandleInvalidSubmit"">
    <DataAnnotationsValidator />
    <div class=""row"">
        <div class=""col-md-6"" style=""padding-bottom: 12px"">
            <label for=""identifier"">Identifier: </label>
            <DxTextBox Id=""identifier"" @bind-Text=""@starship.Identifier"" />
            <ValidationMessage For=""@(() => starship.Identifier)"" />
        </div>
        <div class=""col-md-6"" style=""padding-bottom: 12px"">
            <label for=""classification"">Primary Classification: </label>
            <DxComboBox Id=""classification"" NullText=""Select classification ...""
                        ClearButtonDisplayMode=""DataEditorClearButtonDisplayMode.Auto""
                        Data=""@(new List<Classification>() { new Classification(1, ""Defense""),
                                                             new Classification(2, ""Exploration""),
                                                             new Classification(3, ""Diplomacy"") })""
                        TextFieldName=""Value""
                        ValueFieldName=""Id""
                        @bind-Value=""@starship.Classification"" />
            <ValidationMessage For=""@(() => starship.Classification)"" />
        </div>
        <div class=""col-md-6"" style=""padding-bottom: 12px"">
            <label for=""accommodation"">Maximum Accommodation: </label>
            <DxSpinEdit Id=""accommodation"" @bind-Value=""@starship.MaximumAccommodation"" />
            <ValidationMessage For=""@(() => starship.MaximumAccommodation)"" />
        </div>
        <div class=""col-md-6"" style=""padding-bottom: 12px"">
            <label for=""productionDate"">Production Date: </label>
            <DxDateEdit @bind-Date=""@starship.ProductionDate"" />
            <ValidationMessage For=""@(() => starship.ProductionDate)"" />
        </div>
        <div class=""col-md-12"">
            <DxButton SubmitFormOnClick=""true"" Text=""Submit"" RenderStyle=""ButtonRenderStyle.Secondary"" />
        </div>
    </div>
</EditForm>

@code {
    private Starship starship = new Starship();

    private void HandleValidSubmit()
    {
        Console.WriteLine(""OnValidSubmit"");
    }
    private void HandleInvalidSubmit()
    {
        Console.WriteLine(""OnInvalidSubmit"");
    }
}")
</CodeSnippetTabPage>
<CodeSnippetTabPage Text="Starship">
@(@"public class Starship {
    [Required(ErrorMessage = ""The Identifier value should be specified."")]
    [StringLength(16,
    ErrorMessage = ""The Identifier exceeds 16 characters."")]
    public string Identifier { get; set; }

    [Range(1, 3, ErrorMessage = ""The Primary Classification value should be specified."")]
    public int Classification { get; set; }

    [Range(1, 100000, ErrorMessage = ""The Maximum Accommodation value should be a number between 1 and 100,000."")]
    public int MaximumAccommodation { get; set; }

    [Required]
    [DateInPastAttribute(ErrorMessage = ""The Production Date value cannot be later than today."")]
    public DateTime ProductionDate { get; set; }
}")
</CodeSnippetTabPage>
<CodeSnippetTabPage Text="Classification">
@(@"public class Classification {
    public int Id { get; set; }
    public string Value { get; set; }

    public Classification(int id, string value) {
        Id = id;
        Value = value;
    }

    public override int GetHashCode() {
        int result = 17;
        result = result * 31 + Value.GetHashCode();
        result = result * 31 + Id.GetHashCode();
        return result;
    }

    public override bool Equals(object obj) {
        var item = obj as Classification;
        if (item == null)
            return false;

        return item.Id == Id && item.Value == Value;
    }
}")
</CodeSnippetTabPage>
</CodeSnippetTabbed>
